package com.raising.sc;

import com.raising.sc.config.RibbonConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.cloud.netflix.ribbon.RibbonClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.client.RestTemplate;

/**
 * 这里支持两种 客户端方式
 *
 * @RibbonClients
 *              ribbon扫描所有服务 或者 指定服务
 * @RibbonClient(name = "service-C",configuration = RibbonConfiguration.class)
 *              ribbon 扫描指定服务，与服务的配置
 *
 */
@SpringBootApplication
@EnableDiscoveryClient
//@RibbonClients(defaultConfiguration = )
//@RibbonClients(value = {
//        @RibbonClient(name = "xxx",configuration = XxxRibbonConfig.class),
//        @RibbonClient(name = "demo",configuration = DemoRibbonConfig.class)
//})
@RibbonClient(name = "service-C",configuration = RibbonConfiguration.class)
public class ServiceCRibbonApplication
{
    public static void main( String[] args )
    {
        SpringApplication.run(ServiceCRibbonApplication.class,args);
    }

    /**
     * 向程序的ioc注入一个bean: restTemplate;
     * 通过@LoadBalanced注解表明这个restRemplate开启负载均衡的功能
     */
    @Bean
    @LoadBalanced
    RestTemplate restTemplate(){
        return new RestTemplate();
    }
}
